#include "Require/Init.iss"

function main()
{
	Turbo 1000
	extension -require isxeq2
	EA "Loading" "Wanderbot.iss"
	declare VirtualState string global "ROAM"
	declare CantSeeCount uint global 0
	declare NextTarget uint global
	declare WanderX float global ${Me.X}
	declare WanderZ float global ${Me.Z}
	declare FaceX float global
	declare FaceZ float global
	declare MoveX float global
	declare MoveZ float global
	declare MoveY float global
	declare FirstPointX float global ${Script.ExecuteAtom[addSubtract, ${Me.X}, ${Math.Rand[50]:Inc[50]}]}
	declare FirstPointZ float global ${Script.ExecuteAtom[addSubtract, ${Me.Z}, ${Math.Rand[50]:Inc[50]}]}
	declare SecondPointX float global ${Script.ExecuteAtom[addSubtract, ${Me.X}, ${Math.Rand[40]:Inc[40]}]}
	declare SecondPointZ float global ${Script.ExecuteAtom[addSubtract, ${Me.Z}, ${Math.Rand[10]:Inc[10]}]}
	declare ThirdPointX float global ${Script.ExecuteAtom[addSubtract, ${Me.X}, ${Math.Rand[10]:Inc[10]}]}
	declare ThirdPointZ float global ${Script.ExecuteAtom[addSubtract, ${Me.Z}, ${Math.Rand[60]:Inc[60]}]}
	declare LastPointX float global ${Script.ExecuteAtom[addSubtract, ${Me.X}, ${Math.Rand[60]:Inc[60]}]}
	declare LastPointZ float global ${Script.ExecuteAtom[addSubtract, ${Me.Z}, ${Math.Rand[30]:Inc[30]}]}
	declare NextPointX float global
	declare NextPointZ float global
	declare NextPoint uint global 1
	declare NextPosition string global "ASC"
	declare blacklist collection:string global
	declare MOVEFORWARD string global "num lock"
	declare MOVEBACKWARD string global "s"
	declare STRAFELEFT string global "q"
	declare STRAFERIGHT string global "e"
	declare TURNLEFT string global "a"
	declare TURNRIGHT string global "d"
	declare SWIMDOWN string global "end"
	declare SWIMUP string global "home"
	declare FullInventory bool global FALSE
	ISXEQ2:EnduringBreath[enable]
	ISXEQ2:NoFog[enable]
	call InitializeSettings
	call LoadGUI
	BindTriggers
	while 1
	{
		call Scan
		while ${QueuedCommands}
		{
			ExecuteQueued
			FlushQueued
		}
		;EA "NextTarget" "${NextTarget} : ${Actor[${NextTarget}].Name}"
		waitframe
	}
}
function atexit()
{
	if ${Script[Scan](exists)}
	{
		EndScript Scan
	}
	if ${Script[Fight](exists)}
	{
		EndScript Fight
	}
	if ${Script[Loot](exists)}
	{
		EndScript Loot
	}
	if ${Script[Harvest](exists)}
	{
		EndScript Harvest
	}
	if ${Script[Idle](exists)}
	{
		EndScript Idle
	}
	call StopMoving
	call StoreSettings
	call UnloadGUI
	EA "Unloading" "Wanderbot.iss"
}

atom(script):int addSubtract(int var1, int var2)
{
	
	if ${Math.Rand[10]} < 5
	{
		RETURN ${Math.Calc[${var1}+${var2}]}
	}
	else
	{
		RETURN ${Math.Calc[${var1}-${var2}]}
	}
}